package com.jsoft.jsofted.platform.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.diboot.core.binding.annotation.BindField;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsNotNull;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.annotation.Unique;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.jsoft.jsofted.framework.entity.IdEntity;
import com.jsoft.jsofted.framework.entity.TimeEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Id;
import java.sql.Timestamp;
import java.util.LinkedList;

/**
 * 角色权限表
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Table("sys_role_perm")
@TableName("sys_role_perm")
public class RolePermEntity implements TimeEntity, IdEntity {
    @Id
    @Column
    @TableId(type = IdType.ASSIGN_ID)
    protected Long id;

    @Column
    @IsNotNull
    @Unique(value = "roleMenu", columns = {"role_id", "menu_id"})
    protected Long roleId;

    @TableField(exist = false)
    @BindField(entity = RoleEntity.class, field = "name", condition = "role_id=id")
    protected String roleName;

    @Column
    @IsNotNull
    protected Long menuId;

    @TableField(exist = false)
    @BindField(entity = MenuEntity.class, field = "name", condition = "menu_id=id")
    protected String menuName;

    @TableField(typeHandler = JacksonTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 255)
    protected LinkedList actions;

    @Column
    @IsNotNull
    protected Timestamp createTime;

    @Column
    @IsNotNull
    protected Timestamp updateTime = new Timestamp(System.currentTimeMillis());
}
